<?php
/**
 * 商品详细信息处理模型
 * @author e5
 *
 */
class DetailModel extends Model{
	public $table = "detail";
	/**
	 * 添加
	 * @param unknown $gid
	 */
	public function addDetail($gid){
		$mstr = "";
		$sstr = "";
		foreach (Q("post.piclist") as $v){
			//生成中图
			$medium = substr($v, 0, strripos($v, "."))."_medium";
			$medium .= substr($v, strripos($v, "."));
			$mstr .= $medium.",";
			//生成小图
			$small = substr($v, 0, strripos($v, "."))."_small";
			$small .= substr($v, strripos($v, "."));
			$sstr .= $small.",";
		}
		$this->data['big'] = implode(",", Q("post.piclist"));
		$this->data['medium'] = rtrim($mstr,",");
		$this->data['small'] = rtrim($sstr,",");
		$this->data['intro'] = $_POST['intro'];
		$this->data['service'] = $_POST['service'];
		$this->data['vshop_goods_gid'] = $gid;
		return $this->add();
	}
	//更新
	public function editDetail($gid){
		$mstr = "";
		$sstr = "";
		foreach (Q("post.piclist") as $v){
			//生成中图
			$medium = substr($v, 0, strripos($v, "."))."_medium";
			$medium .= substr($v, strripos($v, "."));
			$mstr .= $medium.",";
			//生成小图
			$small = substr($v, 0, strripos($v, "."))."_small";
			$small .= substr($v, strripos($v, "."));
			$sstr .= $small.",";
		}
		$this->data['big'] = implode(",", Q("post.piclist"));
		$this->data['medium'] = rtrim($mstr,",");
		$this->data['small'] = rtrim($sstr,",");
		$this->data['intro'] = $_POST['intro'];
		$this->data['service'] = $_POST['service'];
		$this->where("vshop_goods_gid={$gid}")->update();
		return true;
	}
}